

import { Component, OnInit, Injector, TemplateRef, ViewChild, Input, Output, EventEmitter } from '@angular/core';
import { NgZorroPageBaseComponent } from '../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import { HttpService } from "../../core/service/http.service";
import { HttpClient } from "@angular/common/http";
import { Router, NavigationExtras } from "@angular/router";
import {
  AndOr, Compare, ExpressionPair, PagedResultDto, PagerSearchInput, ElementViewType, BaseComponentConfig,
  SystemFormControl, FieldType, ElementShowType, CustomNavigation, ClassInfoOutput, NavigatType, ArSystemFormControl, ClassSchool
} from "../..";
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { CityListComponent } from '../school/cityList';
import {
  FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators,
  FormControl
} from "@angular/forms";



@Component({
  selector: 'app-addresch',
  templateUrl: './addresch.component.html',
  styleUrls: ['../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component.scss']
})
export class AddreschComponent extends NgZorroPageBaseComponent implements OnInit {
  @Output() fromdata = new EventEmitter();
  val;
  cityData;
  provinceData;
  manalName;
  resultxy;
  resultxymana;
  listEntitiesdata;
  aclear;
  classmana;
  delesh = [];
  disabledButton = true;
  displayData: Array<{ name: string; age: number; address: string; checked: boolean }> = [];
  dataSet = [];
  checkedNumber = 0;
  operating = false;
  selectedProvince; // 省
  selectedCity; // 市
  schoolName; // 学校
  collegelName; // 院
  facultydata; // 系id
  addresname; // 搜索名字
  userType = true;

  ngOnInit() {
    this.IniObserver.subscribe(sb => {
      this.getEntityList();
    });
    this.listSearchValue = [
      new ExpressionPair('id', "", Compare.Equal, AndOr.And),
      new ExpressionPair('className', "", Compare.Equal, AndOr.And),
    ];
  }
  constructor(
    injecter: Injector,
    public http1: HttpService,
    private modalService: NzModalService,
    public http: HttpClient

  ) {
    super(injecter,
      new BaseComponentConfig(
        "",
        // "ClassInfo/Create",
        // "ClassInfo/Update",
        // "ClassInfo/Get",
        // "ClassInfo/Delete",
        // "id",
        // "ClassInfo",
        // "班级、学生信息管理",
        "",
        "",
        "",
        "",
        "id",
        "",
        "",
        [],
        "",
        { Edit: false, Dell: false },
      ));

    const city = new CityListComponent;
    this.cityData = city.cityDatas;
    this.provinceData = city.provinceDatas;
    // this.loginstatus();


  }
  // loginstatus() {
  //   if (sessionStorage.getItem('userRoleType') === "1") {
  //     // tslint:disable-next-line:prefer-const
  //     const aId = sessionStorage.getItem('academeId');
  //     this.http1.get<any>(`School/GetDepartmentByAcademe?aId=${aId}`).then(e => {
  //       this.resultxymana = e;
  //       });
  //     this.userType = false;
  //   }
  // }
  // 根据省市获取学校
  async citygetschool(e) {
    const ss = this.selectedProvince + "-" + this.selectedCity;
    this.listEntitiesdata = await this.http1.get<any>('School/GetSchoolByAddress?address=' + ss);
  }
  // 根据学校获取学院
  async provinceChangesol(e) {
    this.resultxy = await this.http1.get<any>('School/GetAllAcademeBySchool?input=' + e);
    this.collegelName = "";
  }
  // 根据学院获取系
  async getmana(e) {
    this.resultxymana = await this.http1.get<any>('School/GetDepartmentByAcademe?aId=' + e);

  }

  async searchChange(searchText: string) {
    const that = this;
    clearTimeout(this.aclear);
    this.aclear = setTimeout(() => {
      that.sealist(searchText);
    }, 1000);
  }
  sealist(i) {
    const datalist = { "Name": i };
    this.listEntitiesdata = [];
    this.http1.post<any>("School/GetSchoolToTen", datalist).then(e => {
      this.listEntitiesdata = e;

    });
  }

  getNewEntity(): ClassSchool {
    return new ClassSchool();
  }
  // async editEntity(id: number) {
  //   this.router.navigate(['app/management/schooledit'], {
  //     queryParams: {
  //       smId: id
  //     }
  //   });
  // }


  // get viewType(): ElementViewType {
  //   return this._viewType;

  // }

  // set viewType(value: ElementViewType) {
  //   this.router.navigate(['app/management/schooleditadd']);
  // }
  // async navigateCustom(url: string, pid: any) {
  //   const msgId = this.message.loading('正在获取数据', { nzDuration: 0 }).messageId;
  //   try {
  //     const findEntity = await this.httpService.get<ClassSchool>(`${this.componentConfig.GetSingle}?input=${pid}`);
  //     if (findEntity) {
  //       const navigationExtras: NavigationExtras = {
  //         queryParams: { 'id': pid, 'caption': findEntity.schoolName }
  //       };
  //       this.router.navigate([url], navigationExtras);
  //     } else {
  //       this.message.error('无法确定表单信息！请刷新列表！');
  //     }
  //   }
  //   finally {
  //     this.message.remove(msgId);
  //   }
  // }
  // studentmanage(id: string) {
  //   this.router.navigate(['app/classindex/studentmanage'], {
  //     queryParams: {
  //       classId: id
  //     }
  //   });
  // }
  // editor(id: string) {
  //   this.router.navigate(['app/classindex/classedit'], {
  //     queryParams: {
  //       classId: id
  //     }
  //   });
  // }
  // showModalForComponent(entity: ClassSchool, tag: any) {
  // }
  // 搜索
  // selectedProvince; // 省
  // selectedCity; // 市
  // schoolName; // 学校
  // collegelName; // 院
  // facultydata; // 系id
  // addresname; // 搜索名字
  classsearch() {
    const searchdata = [];
    const addres = this.selectedProvince + "-" + this.selectedCity;
    searchdata.push(addres);
    searchdata.push(this.schoolName);
    searchdata.push(this.collegelName);
    searchdata.push(this.facultydata);
    searchdata.push(this.addresname);
    this.fromdata.emit(searchdata);
    // this.getEntityList();
  }
  // 搜索取消
  classcancle() {
    this.selectedProvince = undefined;
    this.selectedCity = undefined;
    this.schoolName = undefined;
    this.collegelName = undefined;
    this.facultydata = undefined;
    this.addresname = undefined;
    this.listEntitiesdata = [];
    this.resultxy = [];
    this.resultxymana = [];
    // this.loginstatus();
    const search = "fal";
    this.fromdata.emit(search);
  }
  // keydown事件
  classsearchinput(e) {
    if (e.keyCode === 13) {
      this.classsearch();
    }
  }
  // refreshStatus1(id, e): void {
  //   if (e === true) {
  //     this.delesh.push(id);
  //   } else {
  //     for (let i = 0; i < this.delesh.length; i++) {
  //       if (id === this.delesh[i]) {
  //         this.delesh.splice(i, 1);
  //       }
  //     }
  //   }
  //   const allChecked = this.displayData.every(value => value.checked === true);
  //   const allUnChecked = this.displayData.every(value => !value.checked);
  //   this.allChecked = allChecked;
  //   this.indeterminate = (!allChecked) && (!allUnChecked);
  //   this.disabledButton = !this.dataSet.some(value => value.checked);
  //   this.checkedNumber = this.dataSet.filter(value => value.checked).length;
  // }
  // checkAll(value: boolean): void {
  //   this.delesh = [];
  //   this.displayData.forEach(data => data.checked = value);
  //   // tslint:disable-next-line:no-shadowed-variable
  //   const allChecked = this.displayData.every(value => value.checked === true);
  //   // tslint:disable-next-line:no-shadowed-variable
  //   const allUnChecked = this.displayData.every(value => !value.checked);
  //   this.indeterminate = (!allChecked) && (!allUnChecked);
  //   // tslint:disable-next-line:no-shadowed-variable
  //   this.disabledButton = !this.dataSet.some(value => value.checked);
  //   // tslint:disable-next-line:no-shadowed-variable
  //   this.checkedNumber = this.dataSet.filter(value => value.checked).length;
  //   if (value === true) {
  //     for (let i = 0; i < this.listEntities.entities.length; i++) {
  //       this.delesh.push(this.listEntities.entities[i].id);
  //     }
  //   } else {
  //     this.delesh = [];
  //   }
  // }
  // operateData(): void {
  //   this.operating = true;
  //   setTimeout(_ => {
  //     this.dataSet.forEach(value => value.checked = false);
  //     this.refreshStatus1("2", "1");
  //     this.operating = false;
  //   }, 1000);
  // }
  // currentPageDataChange($event: Array<{ name: string; age: number; address: string; checked: boolean }>): void {
  //   this.displayData = $event;
  // }
}
